﻿@model GolfLeague.EditModels.SchedulesEditModel

<script type="text/javascript">
    $(document).ready(function () {
        $('#dialog').dialog({
            autoOpen: false,
            model: true
        });
        $('input:button').button();
        $('input:submit').button();
        $('div#buttonlist a').hover(
		    function () { $(this).addClass('ui-state-hover'); },
		    function () { $(this).removeClass('ui-state-hover'); }
	    );
    });

    $(function () {
        $(".DeleteButton").click(function (e) {
            e.preventDefault();
            var recordToDelete = $(this).attr("id");
            recordToDelete = recordToDelete.replace("delete-", "");

            $("#dialog").dialog("option", "buttons", {
                "Yes": function () {
                    $(this).dialog("close");
                    if (recordToDelete != '') {
                        $.post("/Schedule/ScheduleDelete", { "scheduleID": recordToDelete },
                        function (data) {
                            $('#row-' + recordToDelete).fadeOut('slow');
                        });
                    }
                },
                "No": function () {
                    $(this).dialog("close");
                    return false;
                }
            });
            $("#dialog").dialog("open");
        });
    });

    $(function () {
        $(".RoundsButton").click(function (e) {
            e.preventDefault();
            var detailsRecord = $(this).attr("id");
            detailsRecord = detailsRecord.replace("details-", "");

            if (detailsRecord != '') {
                window.location = '/Round/Index/' + detailsRecord;
            }
        });
    });

    $(function () {
        $(".EditButton").click(function (e) {
            e.preventDefault();
            var recordToEdit = $(this).attr("id");
            recordToEdit = recordToEdit.replace("edit-", "");

            if (recordToEdit != '') {
                window.location = '/Schedule/ScheduleEdit/' + recordToEdit;
            }
        });
    });

</script>

@{
    ViewBag.Title = "Schedules";
}
@Html.ActionLink("Admin Home", "Index") > Schedules<br /><br />
@using (Html.BeginForm())
{
<fieldset>
    <legend>Add New Schedule</legend>
        @Html.HiddenFor(model => model.NewSchedule.ScheduleID)

        <div class="editor-label">
            @Html.LabelFor(model => model.NewSchedule.ScheduleName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.NewSchedule.ScheduleName)
            @Html.ValidationMessageFor(model => model.NewSchedule.ScheduleName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.NewSchedule.ScheduleYear)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.NewSchedule.ScheduleYear, new SelectList(Model.yearList, DateTime.Now.Year))
            @Html.ValidationMessageFor(model => model.NewSchedule.ScheduleYear)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.NewSchedule.HandicapCalculationID)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.NewSchedule.HandicapCalculationID, new SelectList(Model.HandicapDropdown, "dropdownID", "dropdownText", Model.NewSchedule.HandicapCalculationID))
            @Html.ValidationMessageFor(model => model.NewSchedule.HandicapCalculationID)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
        <div id="dialog" title="Confirm Delete">Are you sure you want to delete this schedule?</div>
</fieldset>
}

<fieldset>
    <legend>Schedules</legend>
    <table>
        <tr>
            <th>
                Schedule Name
            </th>
            <th>
                Year
            </th>
            <th>
                Handicap Method
            </th>
            <th></th>
        </tr>

@foreach (var item in Model.Schedules) {
        <tr id="row-@item.ScheduleID">
            <td>
                @item.ScheduleName
            </td>
            <td>
                @item.ScheduleYear
            </td>
            <td>
                @item.HandicapCalculation.HandicapName
            </td>
            <td>
                <input type="button" class="RoundsButton" id="details-@item.ScheduleID" value="Dates" />
                <div id="buttonlist" style="vertical-align:middle">
                    <a href="#" title="Edit Schedule" class="EditButton ui-state-default ui-corner-all ui-icon ui-icon-pencil" id="edit-@item.ScheduleID"></a>
                    <a href="#" title="Delete Schedule" class="DeleteButton ui-state-default ui-corner-all ui-icon ui-icon-trash" id="delete-@item.ScheduleID"></a>
                </div>

            </td>
        </tr>
}
    </table>
</fieldset>
@Html.ActionLink("Back to Admin Home", "Admin", "Home")